package department.fc.controller;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import department.fc.common.AttributeAndView;
import department.fc.common.Controller;
import department.fc.domain.Department;
import department.fc.service.DepartmentService;

public class GetDepartmentByNumController implements Controller{

	@Override
	public AttributeAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
//		1.리퀘스트 받아오기 
		int departmentNum = Integer.parseInt(request.getParameter("departmentNum"));
//		2. 서비스 제공 준비 
		DepartmentService service = DepartmentService.getInstance();
		AttributeAndView av = null;
		
		try {
			Department dept = service.getDepartmentByNum(departmentNum);
			av = new AttributeAndView(false, "/WEB-INF/jsp/dept/department_detail.jsp", "department", dept);
			
		} catch (SQLException e) {
			e.printStackTrace();
			request.setAttribute("error_message", e.getMessage());
			av = new AttributeAndView(false, "/WEB-INF/jsp/error.jsp", "error_message", e.getMessage());
		}
		
		return av;
	}

}
